

use super::common::Name;
use super::common::Json;
use super::animation;
use super::character;


pub trait OutputToDirectory
    where Self: Json
{
    fn write_json_to_directory(&self, save_dir: &str);
}


impl OutputToDirectory for animation::AnimationData
{
    fn write_json_to_directory(&self, save_dir: &str) {
        let mut i:u32 = 0;
        for f in self.get_frames() {
            let path = format!("{}/{}/{}.json", save_dir, self.get_name(), i);
            f.write_json(path.as_str());
            i += 1;
        }
    }
}




impl character::Character
{
    pub fn write_json_to_directory_from_input(&self, count: u32)
    {
        print!("save directory: ");
        let dir = super::common::console::read();
        for _index in 0..count {
            let c = <character::Character as super::common::FromInput>::from_input();
            let path = format!("{}/{}.json", dir, c.get_name());
            c.write_json(path.as_str());
        }
    }

    
}


impl character::GameCharacter
{
    pub fn write_animation_to_directory(&self, save_dir: &str)
    {
        for (k, v) in self.get_animation_manager().get_animation_map()
        {
            let path = format!("{}/{}.json", save_dir, k);
            v.write_json(path.as_str());
        }
    }
}

